package data_type

func SortVector(vec *TypVector, comparator func(i, j int) bool) {
	qsort(vec, comparator, 0, vec.Count()-1)
}

func qsort(vec *TypVector, comparator func(i, j int) bool, l int, r int) {
	if l >= r {
		return
	}
	m := l - 1
	for i := l; i <= r; i++ {
		if !comparator(i, r) {
			m++
			c := vec.Nth(m)
			vec.Buffers[m] = vec.Buffers[i]
			vec.Buffers[i] = c
		}
	}

	qsort(vec, comparator, l, m-1)
	qsort(vec, comparator, m+1, r)
}
